using System;
using System.Collections.Generic;
using System.Text;


using Microsoft.Xna.Framework;
using CreamX.Framework.Attributes;


namespace CreamX.Framework.Game.Components
{
    [CreamXComponentAttribute("CreamXMountPointComponent",ShowInEditor=false)]
    public class CreamXMountPointComponent:CreamXComponent
    {
        public CreamXMountPointComponent()
        {
            _mountPoints = new List<MountPoint>();
        }
        public override object Clone()
        {
            CreamXMountPointComponent mnt = new CreamXMountPointComponent();
            foreach (MountPoint pnt in MountPoints)
            {
                mnt.MountPoints.Add((MountPoint)pnt.Clone());
            }
            return base.Clone();
        }
        public override void OnRegister()
        {
            Enabled = true;
            
            base.OnRegister();
        }
        private List<MountPoint> _mountPoints;

        [CreamXComponentProperty("MountPoints")]
        public List<MountPoint> MountPoints
        {
            get { return _mountPoints; }
            set { _mountPoints = value; }
        }


        internal void AddMountPoint(string name, Vector2 position, float rotation)
        {
            MountPoint mnt = new MountPoint();
            mnt.Name = name;
            mnt.Position = position;
            mnt.Rotation = rotation;
            _mountPoints.Add(mnt);
        }

        internal MountPoint GetMountPoint(string p)
        {
            foreach (MountPoint mnt in _mountPoints)
            {
                if (mnt.Name == p)
                    return mnt;
            }
            return null;
        }

        
    }
    [Serializable]
    public class MountPoint:ICloneable
    {
        
        private string _name;

        public string Name
        {
            get { return _name; }
            set { _name = value; }
        }

        private Vector2 _position;

        public Vector2 Position
        {
            get { return _position; }
            set { _position = value; }
        }

        private float _rotation;

        public float Rotation
        {
            get { return _rotation; }
            set { _rotation = value; }
        }

      

        public MountPoint()
        {
        }

        #region ICloneable Members

        public object Clone()
        {
            MountPoint pnt = new MountPoint();
            pnt.Name=Name;
            pnt.Position = Position;
            pnt.Rotation = Rotation;
            return pnt;
        }

        #endregion
    }
}
